package views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.util.Calendar;
import java.util.Date;
import java.util.EventObject;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.CellEditor;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import calendar_ex.Appointment;
import calendar_ex.CalendarDate;
import calendar_ex.CalendarEx;
import calendar_ex.CalendarTime;

public class WeekView extends JPanel{

	public WeekView(){ 



		String[] headers = {"Time","Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //All headers
		Object[][] rawData = new Object[24][8]; //N.B Object[i][1-8] will contain event descriptions
		for (int i = 0; i < 24; i++){
			rawData[i][0] = new CalendarTime(i,0).toString();
		}
		
		Object[][] displayData = new Object[24][8]; 
		for (int i = 0; i < 24; i++){
			displayData[i][0] = rawData[i][0].toString();	
		}

		//should get the current date and show the whole week
		//get list<appointements> needs a start date and end date
		// the end date is the sat of that week
		// and the start date is the sun
		//tool for finding out current date
		// 
		//looking at what day that is and the appropriate changes to start and end that must be made
		CalendarEx calData = new CalendarEx();
		calData.openCalendar("calendar.txt");
		Calendar calendar = Calendar.getInstance();
		Date today = calendar.getTime();
		int dateDay = today.getDate();
		int dateMonth = today.getMonth();
		int dateYear = today.getYear();
		int hour = calendar.HOUR;

		CalendarDate start = new CalendarDate(4,11,2009);
		CalendarDate end = new CalendarDate(11,11, 2009);


		//process the Date to represent a CalendarDate
		List<Appointment> daysAppointments;
		daysAppointments = calData.getAppointmentsBetweenDates(start,end);
		Iterator itApp = daysAppointments.iterator();

		while(itApp.hasNext()){
			Appointment temp = (Appointment) itApp.next();
			CalendarTime tempStartTime = temp.getStart_time();
			CalendarDate tempDay = temp.date;
			int whichDay = tempDay.getDayInt(tempDay.day, tempDay.month, tempDay.year);
			int tempStartHour = tempStartTime.hr;
			int appLasts = temp.getDuration();
			for(int i = 0; i < appLasts; i++){
				displayData[tempStartHour][whichDay] = temp.description;
				tempStartHour++;
			}
		}
		DefaultTableModel dataModel = new DefaultTableModel(displayData, headers);
		JTable table = new JTable(dataModel);
		table.setRowHeight(30);

		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		JScrollPane wvPanel = new JScrollPane(table);

		wvPanel.setPreferredSize(new Dimension(355,500));
		add(wvPanel);

	}

}